--[[
	发送邀请
]]
local filename = "tableinvite.lua"

local timetool = require "timetool"
local skynet = require "skynet"
local cluster = require "skynet.cluster"
local filelog =require "filelog"

local service = nil
local CMD = {
	service = nil
}

function CMD.process(rid, msgbody)
	if not service then
		service = CMD.service
	end
	-- if service.gamenode == "" or service.table_index <= 0  then return false end

	local invitemsg = {}
	invitemsg.rid			= rid
	invitemsg.rolename		= service.info.rolename
	invitemsg.sex			= service.info.sex
	invitemsg.gamenode		= msgbody.gamenode
	if string.sub(invitemsg.gamenode, -4, -1) ~= "node" then
		invitemsg.gamenode = invitemsg.gamenode .. "node"
	end

	invitemsg.table_index	= msgbody.table_index
	invitemsg.conf_intro	= msgbody.conf_intro
    invitemsg.table_code    = msgbody.table_code

	-- 再给桌内其他人广播
	-- local ridlist = skynet.call(".roletablestate", "get_table_allrid", service.gamenode, service.table_index)
	local ridlist = msgbody.ridlist
	local agent = nil
	for _,v in pairs(ridlist) do
		if v ~= rid then
			agent = skynet.call(".mainnode", "lua", "cmd", "get_agent_by_rid", v)
			if agent then
				skynet.send(agent, "lua", "cmd", "tableinvitenotify", invitemsg)
			end
		end
	end
	return false
end

return CMD